#include "jdir.h"
#include <cstdlib>

namespace JXQ
{

class J_DECL_HIDDEN JDirPrivate
{
public:
	inline JDirPrivate(const JString &path);

public:
	std::mutex mutex;
	JString currentPath;
};

inline JDirPrivate::JDirPrivate(const JString &path) :
	currentPath(path) {}

/*---------------------------------------------------------------------*/

JDir::JDir(const JString &path) :
	d_ptr(new JDirPrivate(path))
{

}

JDir::~JDir()
{
	delete d_ptr;
}

void JDir::setCurrentPath(const JString &path)
{
	if( isDir(path) )
	{
		J_MUTEX_LOCKER(d_ptr->mutex);
		d_ptr->currentPath = path;
	}
	else
		jError() << "JDir: setCurrentPath: path does not exist: " << path;
}

JString JDir::currentPath() const
{
	J_MUTEX_LOCKER(d_ptr->mutex);
	return d_ptr->currentPath;
}

} //namespace JXQ
